//
//  StatusListViewModel.swift
//  sinaBlog
//
//  Created by tianxiangyang on 15/12/19.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit


class StatusListViewModel: NSObject {
    
   
  class func loadStatusData(finished:(statuses:[BlogStatus]?) ->()){
    
        
        let token = UserAccount.loadAccount()?.access_token
        
        if let tk = token {
            
            
//            let AFN = AFHTTPSessionManager()
            
            //https://api.weibo.com/2/statuses/home_timeline.json?access_token=2.00QJNneDIv7X1Bf33a347aa4YOUiCE
            
            let parameters = ["access_token":"2.00QJNneDIv7X1Bf33a347aa4YOUiCE"]
            
            let urlString = "https://api.weibo.com/2/statuses/friends_timeline.json"
            
            
            NetworkTool.sharedTool.requestDictToNetworkingWith(Method.GET, urlString: urlString, parameters: parameters, finished: { (dict, error) -> () in
                if error != nil {
                    
                    return
                    
                }
                
                let array = dict!["statuses"] as? [[String:AnyObject]]
                
                //字典转模型
                
                var statuses = [BlogStatus]()
                
                for modelDict:[String:AnyObject] in array! {
                    
                    let blogStatus = BlogStatus(dict: modelDict)
                    
                    statuses.append(blogStatus)
                    
                    
                }
                
//                self.statusList = statuses
                
                //刷新数据
//                self.tableView.reloadData()
                
                finished(statuses: statuses)
                
                
                
            })
        }
    
    
    
    
    }
    
    
}
